import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { cartListType } from '@/types/cart'
export const useCartStore = defineStore(
  'goodsStore',
  () => {
    const cartList = ref<cartListType[]>([] as cartListType[])
    const settle_order = (List: cartListType[]) => {
      cartList.value = List
    }
    const clear_settle_order = () => {
      cartList.value = []
    }
    return { cartList, settle_order, clear_settle_order }
  },
  {
    persist: {
      // 注意：默认持久化，只在H5端有效，因为默认使用的是localStorage，小程序端不能使用这个API，所以需要重写存取方法，转调给UniApp的持久化方法
      // persist: true,
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, val) {
          uni.setStorageSync(key, val)
        },
      },
    },
  },
)
